<template>
<el-dialog title="续借明细" :close-on-click-modal="false" :visible.sync="visible" width="90%">
    <el-table :data="borrowList" border style="width: 100%;">
        <el-table-column prop="bookDetailId" header-align="center" align="center" label="副本编号" width="80"></el-table-column>
        <el-table-column prop="img" header-align="center" align="center" label="封面" width="120">
            <template slot-scope="scope">
                <img v-if="scope.row.imgUrl" style="width: 100px; height: 100px" :src="scope.row.imgUrl" />
                <span v-else></span>
            </template>
        </el-table-column>
        <el-table-column prop="bookName" header-align="center" align="center" label="图书名称"></el-table-column>
        <el-table-column prop="type" header-align="center" align="center" label="分类" width="50"></el-table-column>
        <el-table-column prop="isbn" header-align="center" align="center" label="ISBN" width="130"></el-table-column>
        <el-table-column prop="author" header-align="center" align="center" label="作者"></el-table-column>
        <el-table-column prop="readerId" header-align="center" align="center" label="读者编号">
        </el-table-column>
        <el-table-column prop="status" header-align="center" align="center" label="借阅状态" width="80">
            <template slot-scope="scope">{{scope.row.status==1?'待归还':''}}</template>
        </el-table-column>
        <el-table-column header-align="center" align="center" label="借阅时间" width="100">
            <template slot-scope="scope">{{scope.row.borrowDate | formatDate}}</template>
        </el-table-column>
        <el-table-column header-align="center" align="center" label="到期时间" width="100">
            <template slot-scope="scope">{{scope.row.expireDate | formatDate}}</template>
        </el-table-column>
        <el-table-column prop="note" header-align="center" align="center" label="备注"></el-table-column>
    </el-table>
    <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确认续借</el-button>
    </span>
</el-dialog>
</template>

<script>
export default {
    data() {
        return {
            visible: false,
            borrowList: [],
        };
    },
    methods: {
        init(data) {
            console.log(data)
            this.visible = true;
            this.borrowList = data;
        },
        // 表单提交
        dataFormSubmit() {
            this.$http({
                url: this.$http.adornUrl(`/generator/tborrow/renew`),
                method: "post",
                data: this.borrowList
            }).then(({
                data
            }) => {
                if (data && data.code === 0) {
                    this.$message({
                        message: "续借成功",
                        type: "success",
                        duration: 1500,
                        onClose: () => {
                            this.visible = false;
                            this.$emit("refreshDataList");
                        },
                    });
                } else {
                    this.$message.error(data.msg);
                }
            });
        },
    },
};
</script>
